import { post, get } from "utils/fetch";

const PREFIX = "/flow-platform";

// 流程查询-待我处理
export const getProTodo = ({
  searchName,
  timeStart,
  timeEnd,
  pageNum,
  pageSize,
  applyUserName,
  ...rest
}) => {
  return post(`/flow-platform/process/todo`, {
    searchName,
    timeStart,
    timeEnd,
    pageNum,
    pageSize,
    applyUserName,
    ...rest,
  });
};

// 流程查询-我已处理
export const getProcessed = ({
  searchName,
  timeStart,
  timeEnd,
  pageNum,
  pageSize,
  processStatus,
  ...rest
}) => {
  return post(`/flow-platform/process/processed`, {
    searchName,
    timeStart,
    timeEnd,
    pageNum,
    pageSize,
    processStatus,
    ...rest,
  });
};

// 流程查询-我的申请
export const getApply = ({
  searchName,
  timeStart,
  timeEnd,
  pageNum,
  pageSize,
  processStatus,
  ...rest
}) => {
  return post(`/flow-platform/process/apply`, {
    searchName,
    timeStart,
    timeEnd,
    pageNum,
    pageSize,
    processStatus,
    ...rest,
  });
};

// 流程处理-详情
// export const getProcessDetail = ({
//   processInstanceId,
// }) => {
//   return get(`/flow-platform/process/${processInstanceId}`, {});
// }

// 流程处理-处理
export const handleTask = (data) => {
  return post(`/flow-platform/task/handle`, data, { messageType: "close" });
};

// 流程处理-暂存
export const handleDraft = (data) => {
  return post(`/flow-platform/task/saveFormDraft`, data, { messageType: "close" });
};

// 流程详情-流程图与基本信息
export const diagramAndInfo = ({ processInstanceId }) => {
  return post(`/flow-platform/process/diagramAndInfo`, { processInstanceId });
};

// 流程详情-流程图与基本信息
export const currentTasks = ({ processInstanceId, pageNum, pageSize }) => {
  return post(`/flow-platform/process/currentTasks`, {
    processInstanceId,
    pageNum,
    pageSize,
  });
};

// 流程详情-处理日志
export const handleLogs = ({ processInstanceId, pageNum, pageSize }) => {
  return post(`/flow-platform/process/handleLogs`, {
    processInstanceId,
    pageNum,
    pageSize,
  });
};

// 流程处理--获取表单信息
export const getTaskform = (data) => {
  return post(`/flow-platform/task/form`, data, { messageType: "close" });
};

// 退回
export const handleTaskRollback = ({
  taskId,
  currentActivityId,
  newActivityId,
  comment,
}) => {
  return post(
    `/flow-platform/task/rollback`,
    { taskId, currentActivityId, newActivityId, comment },
    { messageType: "close" },
  );
};

// 获取退回数据
export const getRollbackList = ({ taskId }) => {
  return post(
    `/flow-platform/task/rollback/list`,
    { taskId },
    { messageType: "close" },
  );
};

// 实例监控-流转记录列表查询
export const getFlowRecords = (data) =>
  post("/flow-platform/monitor/flowRecords/list", data);

// 实例监控-通知日志列表查询
/* data:
 *   "processInstanceId": "1110021", //流程实例ID
 *   "activityId": "t_b_1596772", //任务节点ID
 */
// export const getNoticeLog = data => post("/flow-platform/monitor/noticeLog/list", data);

/**
 * 表单日志
 * @param taskId 任务id
 */

export const getFormLog = ({ taskId }) =>
  post(`${PREFIX}/monitor/task/showForm`, { taskId });

/**
 * 通知日志
 * @param taskId 任务id
 */

export const getNoticeLog = ({ taskId }) =>
  post(`${PREFIX}/monitor/task/listNotice`, { taskId });

/**
 * 节点日志
 * @param taskId 任务id
 */

export const getNodeLog = ({ taskId }) =>
  post(`${PREFIX}/monitor/task/listProcessItem`, { taskId });

/**
 * 实例监控详情-通知日志-重新发送
 * @param ruNoticeChannelId 渠道id
 */

export const reSendNoticeMessage = ({ ruNoticeChannelId }) =>
  post(`${PREFIX}/notice/template/reSendNoticeMessage`, { ruNoticeChannelId });

// 我的申请-撤回
export const recall = (data) => {
  return post(`/flow-platform/process/recall`, data, { messageType: "close" });
};

// 我的申请-驳回
export const reject = (data) => {
  return post(`/flow-platform/task/rollback`, data, { messageType: "close" });
};

// 我的申请-催办
export const remind = (data) => {
  return post(`/flow-platform/process/remind`, data, { messageType: "close" });
};

// 我的待办-签收
export const handleTaskclaim = (data) => {
  return post(`/flow-platform/task/claim`, data, { messageType: "close" });
};

// 我的待办-加签
export const addSignTask = (data) => {
  return post(`/flow-platform/task/addSignTask`, data, {
    messageType: "close",
  });
};

// 我的待办-转办
export const turnTask = (data) => {
  return post(`/flow-platform/task/turnTask`, data, { messageType: "close" });
};

// 我的待办-延期
export const delayTask = (data) => {
  return post(`/flow-platform/task/delayTask`, data, { messageType: "close" });
};

// 我的待办-获取延期时间
export const getTaskTimeout = (data) => {
  return get(`/flow-platform/task/getTaskTimeout`, data, {
    messageType: "close",
  });
};

// 我的待办-获取流程发起表单
export const getStartFormDetail = (data) => {
  return get(`/flow-platform/process/getStartFormDetail`, data, {
    messageType: "close",
  });
};

// 审批流程模版-基本信息
export const getProcess = ({ processInstanceId }) => {
  return post(`/flow-platform/process/diagramAndInfo`, { processInstanceId });
};

// 通过 驳回
export const handleCompleteWorkItem = (data) => {
  return post(`/flow-platform/task/handle`, data, { messageType: "close" });
};

// 处理
export const handleWithClaim = (data) => {
  return post(`/flow-platform/task/handleWithClaim`, data, { messageType: "close" });
};

// 终止
export const terminateProcessInstance = (data) => {
  return post(`/flow-platform/api/v1.0/public/terminateProcessInstance`, data, { messageType: "close" });
};

// 获取当前节点之后的任务
export const getNextTaskList = (data) => {
  return post(`/flow-platform/task/skip/list`, data, { messageType: "close" });
};

// 节点跳跃
export const skip = (data) => {
  return post(`/flow-platform/task/skip`, data, { messageType: "close" });
};

// 转办工单
export const dispatchWorkItem = (data) => {
  return post(`/flow-platform/task/turnTask`, data, { messageType: "close" });
};

// 指定下一节点处理人
export const nextNodeAssignee = (data) => {
  return post(`/flow-platform/task/nextNodeAssignee`, data, { messageType: "close" });
};

//  委派
export const delegateTask = (data) => {
  return post(`/flow-platform/task/delegateTask`, data, { messageType: "close" });
};

// 判断内置外置表单
export const isExternalForm = (params) => {
  return post("/flow-platform/form/isExternalForm", params, { messageType: "close" });
};

// 获取外置表单信息
export const getExternalForm = (params) => {
  return get(`/flow-platform/form/externalFormInfo`, params, { messageType: "close" });
};

// 获取用户填写的外部表单详情
 export const filledExternalFormInfo = (params) =>
   get(`${PREFIX}/form/filledExternalFormInfo`, params, { messageType: "close" });

// 获取任务节点外置表单历史
 export const historyExternalTaskForm = (params) =>
   get(`${PREFIX}/form/historyExternalTaskForm`, params, { messageType: "close" });

// 获取开始节点外置表单历史
 export const historyExternalProcessForm = (params) =>
   get(`${PREFIX}/form/historyExternalProcessForm`, params, { messageType: "close" });

// 查询员工信息
export const selectEmployeeList = (data) => post(`/flow-platform/api/v1.0/public/selectEmployeeList`, data);

// 获取指定下一节点
export const getNextTaskDetail = (taskId) => post(`/flow-platform/task/getSpecifyTheNodeHandlerTask?taskId=${taskId}`);

// 保存下一节点
export const postNextNodeAssignee = (params) => post('/flow-platform/task/nextNodeAssignee', params);

// 退回到上一节点
export const rollbackToPreNode = (params) => {
  return post("/flow-platform/api/v1.0/public/rollbackToPreNode", params, { messageType: "close" });
};

// 退回给第一个审批节点
export const rollbackToFirstNode = (params) => {
  return post("/flow-platform/api/v1.0/public/rollbackToFirstNode", params, { messageType: "close" });
};


// 获取指定节点的下级备选
export const getCandidateInfoList = (data) => {
  const {type='',code='', processInstanceId=''} = data;
  return post(`/flow-platform/task/getCandidateInfoList?type=${type}&code=${code}&processInstanceId=${processInstanceId}`);
};

// 根据taskId和userCode判断userCode对应的用户是否是task的候选人
export const queryCandidateTask = (data) => {
  return post(`/flow-platform/api/v1.0/public/queryCandidateTask`, data);
};

// 自定义标题
export const getCustomTitleList = () => {
  return get(`/flow-platform/custom-title/getCustomTitleList`);
};

// 获取是否前置表态
export const getMustExpress =(data) => post('/flow-platform/api/v1.0/public/MustExpress', data);

//  拿回
export const takeBack =(data) => post('/flow-platform/task/takeBack', data);

// 阅办选人
export const dealReadDoData = (params) => {
  return post("/flow-platform/api/v1.0/public/dealReadDoData", params, { messageType: "close" });
};
// 审批流程模版-附件列表
export const getAttachInfoList = (params) => {
  return post(`/flow-platform/process/getAttachInfoList`, params, { messageType: "close" });
};

// 已读
export const updateReadFlag = (params) => {
  const {taskId='', userCode=''} = params;
  return post(`/flow-platform/task/todoTaskupdateReadFlag?taskId=${taskId}&userCode=${userCode}`);
};
